import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export const constantRoutes = [ //常规配置
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login', //登录页面
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/home', //布局页
    name: 'home',
    redirect: '/index',
    meta: {
      roles: ['input', 'approve']
    },
    component: () => import('@/layout/index.vue'),
  }
]
export const asyncRoutes = [ //异步路由  
  {
    path: '/index', //首页
    name: 'index',
    meta: {
      title: '首页',
      roles: ['input', 'approve']
    },
    component: () => import('@/views/home/index.vue')
  },
  {
    path: '/loan-input', //贷款申请
    name: 'loan-input',
    meta: {
      title: '贷款申请',
      roles: ['input']
    },
    component: () => import('@/views/loan-input/index.vue')
  },
  {
    path: '/input-manager', //申请管理
    name: 'input-manager',
    meta: {
      title: '申请管理',
      roles: ['input']
    },
    component: () => import('@/views/input-manager/index.vue')
  },
  {
    path: '/loan-approve', //贷款审批
    name: 'loan-approve',
    meta: {
      title: '贷款审批',
      roles: ['approve']
    },
    component: () => import('@/views/loan-approve/index.vue'),
    children: [{
        path: '/loan-approve/first', //终审
        name: 'first',
        meta: {
          title: '初审'
        },
        component: () => import('@/views/loan-approve/first.vue')
      },
      {
        path: 'end', //终审
        name: 'end',
        meta: {
          title: '终审'
        },
        component: () => import('@/views/loan-approve/end.vue')
      }
    ]
  },
  {
    path: '/contract', //标的管理
    name: 'contract',
    meta: {
      title: '标的管理',
      roles: ['approve']
    },
    component: () => import('@/views/contract/index.vue')
  },
  {
    path: '/permission', //贷款审批
    name: 'permission',
    meta: {
      title: '贷款审批'
    },
    component: () => import('@/views/loan-approve/index.vue'),
    children: [{
        path: 'create', //创建管理员
        name: 'create',
        meta: {
          title: '创建管理员'
        },
        component: () => import('@/views/permission/create.vue')
      },
      {
        path: 'list', //列表展示
        name: 'list',
        meta: {
          title: '列表展示'
        },
        component: () => import('@/views/permission/list.vue')
      }
    ]
  },
]

const router = new VueRouter({
  routes: constantRoutes
})
export default router